package com.app.qbake.module.mine.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.wind.base.BaseActivity;
import com.wind.base.utils.ActivityUtil;
import com.wind.base.utils.Navigator;
import com.wind.base.utils.ViewInflater;
import com.wind.data.mine.bean.AlipayAccount;
import com.app.qbake.R;
import com.app.qbake.module.mine.event.EditAlipayAccountSuccessEvent;
import com.wind.view.ValidateEditText;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by wind on 2018/10/20.
 */

public class EditAlipayAccountActivity extends BaseActivity {
    public static void start(Context context){
        Navigator.navigate(context,EditAlipayAccountActivity.class,null);
    }
    public static void start(Context context,AlipayAccount account){
        Navigator.navigate(context,EditAlipayAccountActivity.class,account);
    }
    @BindView(R.id.et_account)
    ValidateEditText et_account;

    @BindView(R.id.et_name)
    ValidateEditText et_name;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_edit_alipay_account);
        ButterKnife.bind(this);

        AlipayAccount account=Navigator.getSerializableExtra(this);
        if (account!=null) {
            ViewInflater.inflateText(et_account, account.getAccount_number());
            ViewInflater.inflateText(et_name, account.getAccount_name());
        }
    }

    @OnClick(R.id.tv_confirm)
    public void onViewClick(View view){
        if (validate()){
            AlipayAccount account=new AlipayAccount();
            account.setAccount_name(getText(et_name));
            account.setAccount_number(getText(et_account));
            EventBus.getDefault().post(new EditAlipayAccountSuccessEvent(account));
            ActivityUtil.finish(this);
        }
    }

    private boolean validate() {
        return et_account.validate("请输入支付宝账号") && et_name.validate("请输入你的名字");
    }

    @Override
    protected void setTitle() {
        mTitleBar.setTitle("支付宝账号");
    }
}
